home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / heap.com / HEAPPAT5.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1989-03-11  |  4.8 KB  |  161 lines

  1. {*****************************************************************************
  2.  This program patches TPC.EXE, version 5.0. The resulting command line
  3.  compiler can produce additional code to call a user-supplied routine whenever
  4.  a pointer is dereferenced. The user-supplied routine can perform any of a
  5.  variety of operations: error-checking the pointer, transparently supporting
  6.  handle-based pointers for heap compaction, or implementing a complete virtual
  7.  heap in EMS or on disk.
  8.  
  9.  To use this program, compile it and run it from a directory where a copy of
  10.  TPC.EXE resides. The program directly changes TPC.EXE -- no backup is made.
  11.  The program works only on version 5.00 of Turbo Pascal, which to our
  12.  knowledge is the only released version of Turbo 5. We have not developed a
  13.  similar patch for TURBO.EXE -- that would be possible, but the integrated
  14.  compiler is linked differently, making it a chore to find the patch
  15.  locations.
  16.  
  17.  If the patching program halts with an error, be sure to restore a fresh copy
  18.  of TPC.EXE from a backup. At the time of the error, the compiler may be
  19.  partially patched.
  20.  
  21.  For further information on using the patched compiler, refer to HEAP.DOC.
  22.  
  23.  Written 3/8/89, Kim Kokkonen, TurboPower Software.
  24.  Compuserve ID 72457,2131
  25.  Copyright (C) TurboPower Software, 1989. All rights reserved.
  26.  May be distributed freely, but not commercially without express permission
  27.  of TurboPower Software.
  28.  
  29.  Version 1.0
  30.    First release.
  31.  Version 5.0
  32.    Updated for Turbo Pascal 5.0.
  33. *****************************************************************************}
  34.  
  35. {$R-,S-,I+,F-,B-,V-}
  36.  
  37. program HeapPatch;
  38.  
  39. const
  40.   DerefInterrupt = $66; {Change this constant to use a different
  41.                          interrupt number to call the user routine}
  42.  
  43. var
  44.   f : file of Byte;
  45.  
  46.   procedure Abort;
  47.   begin
  48.     WriteLn('Cannot complete patch. Be sure to restore a clean copy of TPC.EXE');
  49.     Halt(1);
  50.   end;
  51.  
  52.   procedure P(loc : LongInt; o, n : Byte);
  53.   var
  54.    b : Byte;
  55.   begin
  56.     Seek(f, loc);
  57.     Read(f, b);
  58.     if b <> o then begin
  59.       WriteLn('At address ',loc, ' expected data:', o, ' but found:', b);
  60.       Abort;
  61.     end;
  62.     Seek(f, loc);
  63.     Write(f, n);
  64.   end;
  65.  
  66. begin
  67.   Assign(f, 'TPC.EXE');
  68.   Reset(f);
  69.   if FileSize(f) <> 56925 then begin
  70.     WriteLn('Unknown version of TPC.EXE');
  71.     Abort;
  72.   end;
  73.  
  74.   {Patch to support pointer checking}
  75.   P($0000046D,$4D,$50);           {Allow /$P+ on command line}
  76.   P($00000470,$E8,$BA);           {...at expense of /$M}
  77.   P($00000471,$53,$08);
  78.   P($00000473,$72,$EB);
  79.   P($00000474,$33,$D9);
  80.  
  81.   P($00000898,$BF,$C3);           {Disable TPC patch checker}
  82.  
  83.   P($000008F6,$90,$00);           {Expanded copy of switch_dir_table}
  84.   P($000008F8,$90,$40);
  85.   P($000008F9,$90,$00);
  86.   P($000008FA,$90,$00);
  87.   P($000008FB,$90,$81);
  88.   P($000008FC,$90,$00);
  89.   P($000008FD,$90,$00);
  90.   P($000008FE,$90,$00);
  91.   P($000008FF,$90,$84);
  92.   P($00000900,$90,$00);
  93.   P($00000901,$90,$00);
  94.   P($00000902,$90,$00);
  95.   P($00000903,$90,$00);
  96.   P($00000904,$90,$20);
  97.   P($00000905,$90,$00);
  98.   P($00000906,$90,$01);
  99.   P($00000907,$90,$00);
  100.   P($00000908,$90,$00);
  101.   P($00000909,$90,$00);
  102.   P($0000090A,$90,$00);
  103.   P($0000090B,$90,$00);
  104.   P($0000090C,$90,$00);
  105.   P($0000090D,$90,$00);
  106.   P($0000090E,$90,$00);
  107.   P($0000090F,$90,$82);
  108.   P($00000910,$90,$00);
  109.   P($00000911,$90,$00);
  110.   P($00000912,$90,$80);
  111.   P($00000913,$90,$80);
  112.   P($00000914,$90,$00);
  113.   P($00000915,$90,$88);
  114.   P($00000916,$90,$02);
  115.   P($00000917,$90,$00);
  116.   P($00000918,$90,$04);
  117.   P($00000919,$90,$00);
  118.   P($0000091A,$90,$00);
  119.   P($0000091B,$90,$00);
  120.   P($0000091C,$90,$10);
  121.   P($0000091D,$90,$00);
  122.   P($0000091E,$90,$08);
  123.   P($0000091F,$90,$00);
  124.   P($00000920,$90,$F7);
  125.   P($00000921,$90,$06);
  126.   P($00000922,$90,$20);
  127.   P($00000923,$90,$19);
  128.   P($00000924,$90,$08);           {New option mask for $P directive}
  129.   P($00000925,$90,$00);
  130.  
  131.   P($00000926,$90,$74);           {Generate DerefInterrupt code}
  132.   P($00000927,$90,$06);
  133.   P($00000928,$90,$B8);
  134.   P($00000929,$90,$CD);
  135.   P($0000092A,$90,DerefInterrupt);
  136.   P($0000092B,$90,$E8);
  137.   P($0000092C,$90,$F6);
  138.   P($0000092D,$90,$6B);
  139.   P($0000092E,$90,$E9);
  140.   P($0000092F,$90,$A9);
  141.   P($00000930,$90,$6B);
  142.  
  143.   P($000044E4,$F4,$3A);           {Jump to DerefInterrupt generator}
  144.   P($000044E5,$2F,$C4);
  145.  
  146.   P($00008C95,$81,$F6);           {Refer to relocated switch_dir_table}
  147.   P($00008C96,$8E,$06);
  148.  
  149.   P($00008D89,$81,$F6);           {Refer to relocated switch_dir_table}
  150.   P($00008D8A,$8E,$06);
  151.  
  152.   P($00009080,$00,$01);           {Add $P as an acceptable switch directive}
  153.   P($00009081,$00,$50);
  154.   P($00009082,$90,$00);
  155.  
  156.   P($0000C9E9,$20,$50);           {Modify compiler version number}
  157.  
  158.   Close(f);
  159.   WriteLn('TPC.EXE 5.0 patched for pointer-dereference interrupts');
  160. end.
  161.